<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>File Source for BuanModelRelation.php</title>
	<link rel="stylesheet" type="text/css" href="../media/style.css">
	<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
</head>
<body>

<table border="0" cellspacing="0" cellpadding="0" height="48" width="100%">
  <tr>
	<td class="header-top-left"><img src="../media/logo.png" border="0" alt="phpDocumentor " /></td>
    <td class="header-top-right">Buan<br /><div class="header-top-right-subpackage"></div></td>
  </tr>
  <tr><td colspan="2" class="header-line"><img src="../media/empty.png" width="1" height="1" border="0" alt=""  /></td></tr>
  <tr>
    <td colspan="2" class="header-menu">
      
                        
                      		[ <a href="../classtrees_Buan.html" class="menu">class tree: Buan</a> ]
		[ <a href="../elementindex_Buan.html" class="menu">index: Buan</a> ]
            [ <a href="../elementindex.html" class="menu">all elements</a> ]
    </td>
  </tr>
  <tr><td colspan="2" class="header-line"><img src="../media/empty.png" width="1" height="1" border="0" alt=""  /></td></tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="195" class="menu">
		<div class="package-title">Buan</div>
  <div class="package">
	<div id="todolist">
			<p><a href="../todolist.html">Todo List</a></p>
	</div>
	</div>
      <b>Packages:</b><br />
  <div class="package">
              <a href="../li_Buan.html">Buan</a><br />
      	</div>
      <br />
                        <br />
                      </td>
    <td>
      <table cellpadding="10" cellspacing="0" width="100%" border="0"><tr><td valign="top">

<h1 align="center">Source for file BuanModelRelation.php</h1>
<p>Documentation is available at <a href="../Buan/_BuanModelRelation.php.html">BuanModelRelation.php</a></p>
<div class="src-code"><span class="php">
<ol><li><div class="src-line"><a name="a1"></a><span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line"><a name="a2"></a><span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a3"></a><span class="src-doc">*&nbsp;</span><span class="src-doc-coretag">@package</span><span class="src-doc">&nbsp;Buan</span></div></li>
<li><div class="src-line"><a name="a4"></a><span class="src-doc">*/</span></div></li>
<li><div class="src-line"><a name="a5"></a>namespace&nbsp;<span class="src-id">Buan</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a6"></a><span class="src-key">class&nbsp;</span><a href="../Buan/ModelRelation.html">ModelRelation</a>&nbsp;<span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a7"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a8"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a9"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@constant&nbsp;int&nbsp;NONE</span></div></li>
<li><div class="src-line"><a name="a10"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Describes&nbsp;a&nbsp;non-existent&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a11"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a12"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">const&nbsp;</span><span class="src-id">NONE&nbsp;</span>=&nbsp;<span class="src-num">0</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a13"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a14"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a15"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@constant&nbsp;int&nbsp;ONE_TO_ONE</span></div></li>
<li><div class="src-line"><a name="a16"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Describes&nbsp;a&nbsp;1:1&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a17"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a18"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">const&nbsp;</span><span class="src-id">ONE_TO_ONE&nbsp;</span>=&nbsp;<span class="src-num">1</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a19"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a20"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a21"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@constant&nbsp;int&nbsp;ONE_TO_MANY</span></div></li>
<li><div class="src-line"><a name="a22"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Describes&nbsp;a&nbsp;1:M&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a23"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a24"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">const&nbsp;</span><span class="src-id">ONE_TO_MANY&nbsp;</span>=&nbsp;<span class="src-num">2</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a25"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a26"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a27"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@constant&nbsp;int&nbsp;MANY_TO_ONE</span></div></li>
<li><div class="src-line"><a name="a28"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Describes&nbsp;a&nbsp;M:1&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a29"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a30"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">const&nbsp;</span><span class="src-id">MANY_TO_ONE&nbsp;</span>=&nbsp;<span class="src-num">3</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a31"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a32"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a33"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@constant&nbsp;int&nbsp;MANY_TO_MANY</span></div></li>
<li><div class="src-line"><a name="a34"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Describes&nbsp;a&nbsp;M:M&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a35"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a36"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">const&nbsp;</span><span class="src-id">MANY_TO_MANY&nbsp;</span>=&nbsp;<span class="src-num">4</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a37"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a38"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a39"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@constant&nbsp;string&nbsp;REF_DEFAULT</span></div></li>
<li><div class="src-line"><a name="a40"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Default&nbsp;reference&nbsp;to&nbsp;use&nbsp;in&nbsp;relationships.</span></div></li>
<li><div class="src-line"><a name="a41"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a42"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">const&nbsp;</span><span class="src-id">REF_DEFAULT&nbsp;</span>=&nbsp;<span class="src-str">'__default__'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a43"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a44"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a45"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@constant&nbsp;string&nbsp;REF_PARENT</span></div></li>
<li><div class="src-line"><a name="a46"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Reference&nbsp;used&nbsp;in&nbsp;the&nbsp;1:M&nbsp;side&nbsp;of&nbsp;a&nbsp;recursive&nbsp;1:M&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a47"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;This&nbsp;is&nbsp;just&nbsp;a&nbsp;convenience&nbsp;alias&nbsp;for&nbsp;self::REF_DEFAULT,&nbsp;and&nbsp;is&nbsp;meant</span></div></li>
<li><div class="src-line"><a name="a48"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;to&nbsp;provide&nbsp;code&nbsp;clarity&nbsp;in&nbsp;some&nbsp;situations.</span></div></li>
<li><div class="src-line"><a name="a49"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a50"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">const&nbsp;</span><span class="src-id">REF_PARENT&nbsp;</span>=&nbsp;<span class="src-str">'__default__'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a51"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a52"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a53"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@constant&nbsp;string&nbsp;REF_CHILD</span></div></li>
<li><div class="src-line"><a name="a54"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Reference&nbsp;used&nbsp;in&nbsp;the&nbsp;M:1&nbsp;side&nbsp;of&nbsp;a&nbsp;recursive&nbsp;1:M&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a55"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a56"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">const&nbsp;</span><span class="src-id">REF_CHILD&nbsp;</span>=&nbsp;<span class="src-str">'__child__'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a57"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a58"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a59"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@property&nbsp;int&nbsp;$cardinality</span></div></li>
<li><div class="src-line"><a name="a60"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;The&nbsp;cardinality&nbsp;of&nbsp;$this&nbsp;relationship&nbsp;(one&nbsp;of&nbsp;the&nbsp;class&nbsp;constants)</span></div></li>
<li><div class="src-line"><a name="a61"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a62"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">private&nbsp;</span><a href="../Buan/ModelRelation.html#var$cardinality">$cardinality</a>&nbsp;=&nbsp;<span class="src-id">NULL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a63"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a64"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a65"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@property&nbsp;bool&nbsp;isRecursive</span></div></li>
<li><div class="src-line"><a name="a66"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Indicates&nbsp;if&nbsp;this&nbsp;is&nbsp;a&nbsp;recursive&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a67"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;A&nbsp;recursive&nbsp;relationship&nbsp;is&nbsp;when&nbsp;a&nbsp;Model&nbsp;has&nbsp;a&nbsp;foreign-key&nbsp;pointing&nbsp;to&nbsp;an</span></div></li>
<li><div class="src-line"><a name="a68"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;instance&nbsp;of&nbsp;the&nbsp;same&nbsp;Model.&nbsp;This&nbsp;would&nbsp;be&nbsp;common&nbsp;in&nbsp;a&nbsp;nested&nbsp;directory</span></div></li>
<li><div class="src-line"><a name="a69"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;structure,&nbsp;for&nbsp;example.</span></div></li>
<li><div class="src-line"><a name="a70"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a71"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">private&nbsp;</span><a href="../Buan/ModelRelation.html#var$isRecursive">$isRecursive</a>&nbsp;=&nbsp;<span class="src-id">FALSE</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a72"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a73"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a74"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@property&nbsp;int&nbsp;$limit</span></div></li>
<li><div class="src-line"><a name="a75"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;In&nbsp;a&nbsp;1:M&nbsp;relationship,&nbsp;this&nbsp;defines&nbsp;the&nbsp;limit&nbsp;of&nbsp;Models&nbsp;on&nbsp;the&nbsp;&quot;M&quot;&nbsp;side&nbsp;of</span></div></li>
<li><div class="src-line"><a name="a76"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;the&nbsp;relationship</span></div></li>
<li><div class="src-line"><a name="a77"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a78"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">private&nbsp;</span><a href="../Buan/ModelRelation.html#var$limit">$limit</a>&nbsp;=&nbsp;<span class="src-id">NULL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a79"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a80"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a81"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@property&nbsp;string&nbsp;$modelSource</span></div></li>
<li><div class="src-line"><a name="a82"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;The&nbsp;name&nbsp;of&nbsp;the&nbsp;Model&nbsp;on&nbsp;the&nbsp;LEFT&nbsp;of&nbsp;a&nbsp;relationship&nbsp;(ie.&nbsp;the&nbsp;&quot;1&quot;&nbsp;in&nbsp;a</span></div></li>
<li><div class="src-line"><a name="a83"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&quot;1:M&quot;&nbsp;relationship)</span></div></li>
<li><div class="src-line"><a name="a84"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a85"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">private&nbsp;</span><a href="../Buan/ModelRelation.html#var$modelSource">$modelSource</a>&nbsp;=&nbsp;<span class="src-id">NULL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a86"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a87"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a88"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@property&nbsp;string&nbsp;$modelTarget</span></div></li>
<li><div class="src-line"><a name="a89"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;The&nbsp;name&nbsp;of&nbsp;the&nbsp;Model&nbsp;on&nbsp;the&nbsp;RIGHT&nbsp;of&nbsp;a&nbsp;relationship&nbsp;(ie.&nbsp;the&nbsp;&quot;M&quot;&nbsp;in&nbsp;a</span></div></li>
<li><div class="src-line"><a name="a90"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&quot;1:M&quot;&nbsp;relationship)</span></div></li>
<li><div class="src-line"><a name="a91"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a92"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">private&nbsp;</span><a href="../Buan/ModelRelation.html#var$modelTarget">$modelTarget</a>&nbsp;=&nbsp;<span class="src-id">NULL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a93"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a94"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a95"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@property&nbsp;string&nbsp;$modelLink</span></div></li>
<li><div class="src-line"><a name="a96"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;The&nbsp;name&nbsp;of&nbsp;the&nbsp;Model&nbsp;that&nbsp;links&nbsp;$modelSource&nbsp;and&nbsp;$modelTarget&nbsp;in&nbsp;a&nbsp;M:M</span></div></li>
<li><div class="src-line"><a name="a97"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a98"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Can&nbsp;also&nbsp;be&nbsp;used&nbsp;in&nbsp;1:M&nbsp;and&nbsp;M:1&nbsp;relationships&nbsp;that&nbsp;are&nbsp;part&nbsp;of&nbsp;a&nbsp;M:M</span></div></li>
<li><div class="src-line"><a name="a99"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;relationship&nbsp;to&nbsp;hold&nbsp;the&nbsp;name&nbsp;of&nbsp;the&nbsp;Model&nbsp;that&nbsp;features&nbsp;in&nbsp;the&nbsp;other</span></div></li>
<li><div class="src-line"><a name="a100"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&quot;half&quot;&nbsp;of&nbsp;the&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a101"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a102"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">private&nbsp;</span><a href="../Buan/ModelRelation.html#var$modelLink">$modelLink</a>&nbsp;=&nbsp;<span class="src-id">NULL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a103"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a104"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a105"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@property&nbsp;string&nbsp;$reference</span></div></li>
<li><div class="src-line"><a name="a106"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Custom&nbsp;reference&nbsp;for&nbsp;this&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a107"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Used&nbsp;if&nbsp;several&nbsp;table&nbsp;columns&nbsp;from&nbsp;Model&nbsp;A&nbsp;all&nbsp;point&nbsp;to&nbsp;Model&nbsp;B.</span></div></li>
<li><div class="src-line"><a name="a108"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a109"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">private&nbsp;</span><a href="../Buan/ModelRelation.html#var$reference">$reference</a>&nbsp;=&nbsp;<span class="src-id">NULL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a110"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a111"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a112"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@property&nbsp;string&nbsp;$nativeKey</span></div></li>
<li><div class="src-line"><a name="a113"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Holds&nbsp;the&nbsp;name&nbsp;of&nbsp;the&nbsp;field&nbsp;involved&nbsp;in&nbsp;the&nbsp;LEFT&nbsp;side&nbsp;of&nbsp;the&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a114"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a115"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">private&nbsp;</span><a href="../Buan/ModelRelation.html#var$nativeKey">$nativeKey</a>&nbsp;=&nbsp;<span class="src-id">NULL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a116"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a117"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a118"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@property&nbsp;string&nbsp;$foreignKey</span></div></li>
<li><div class="src-line"><a name="a119"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Hodls&nbsp;the&nbsp;name&nbsp;of&nbsp;the&nbsp;field&nbsp;involved&nbsp;in&nbsp;the&nbsp;RIGHT&nbsp;side&nbsp;of&nbsp;the&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a120"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a121"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">private&nbsp;</span><a href="../Buan/ModelRelation.html#var$foreignKey">$foreignKey</a>&nbsp;=&nbsp;<span class="src-id">NULL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a122"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a123"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a124"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@property&nbsp;array&nbsp;$options</span></div></li>
<li><div class="src-line"><a name="a125"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Holds&nbsp;a&nbsp;list&nbsp;of&nbsp;options&nbsp;that&nbsp;have&nbsp;been&nbsp;set&nbsp;on&nbsp;this&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a126"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Valid&nbsp;options&nbsp;are:</span></div></li>
<li><div class="src-line"><a name="a127"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;nocascade&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;Used&nbsp;in&nbsp;1:M&nbsp;relationships.&nbsp;Prevents&nbsp;the&nbsp;Model&nbsp;instances&nbsp;on&nbsp;the</span></div></li>
<li><div class="src-line"><a name="a128"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&quot;M&quot;&nbsp;side&nbsp;from&nbsp;being&nbsp;deleted&nbsp;when&nbsp;the&nbsp;&quot;1&quot;&nbsp;side&nbsp;is&nbsp;deleted.</span></div></li>
<li><div class="src-line"><a name="a129"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a130"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">private&nbsp;</span><a href="../Buan/ModelRelation.html#var$options">$options</a>&nbsp;=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a131"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a132"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a133"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@property&nbsp;array&nbsp;$relationships</span></div></li>
<li><div class="src-line"><a name="a134"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Stores&nbsp;ModelRelation&nbsp;objects&nbsp;that&nbsp;describe&nbsp;the&nbsp;relationships&nbsp;between&nbsp;any</span></div></li>
<li><div class="src-line"><a name="a135"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;two&nbsp;Models.</span></div></li>
<li><div class="src-line"><a name="a136"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;This&nbsp;is&nbsp;a&nbsp;multi-dimensional&nbsp;array&nbsp;with&nbsp;indexes&nbsp;in&nbsp;the&nbsp;format:</span></div></li>
<li><div class="src-line"><a name="a137"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;['model-source']['model-target']&nbsp;=&nbsp;ModelRelation&nbsp;instance</span></div></li>
<li><div class="src-line"><a name="a138"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;eg:</span></div></li>
<li><div class="src-line"><a name="a139"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;['Book']['Author']&nbsp;=&nbsp;[object&nbsp;describing&nbsp;this&nbsp;M:M&nbsp;relationship]</span></div></li>
<li><div class="src-line"><a name="a140"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a141"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">static&nbsp;</span><span class="src-key">public&nbsp;</span><a href="../Buan/ModelRelation.html#var$relationships">$relationships</a>&nbsp;=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a142"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a143"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a144"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;void&nbsp;__construct(&nbsp;array&nbsp;$params&nbsp;)</span></div></li>
<li><div class="src-line"><a name="a145"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;$params&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;Contains&nbsp;following&nbsp;elements&nbsp;(*&nbsp;=&nbsp;required):</span></div></li>
<li><div class="src-line"><a name="a146"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;$modelSource*&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;Name&nbsp;of&nbsp;Model&nbsp;on&nbsp;the&nbsp;LEFT&nbsp;side&nbsp;of&nbsp;the&nbsp;relationship</span></div></li>
<li><div class="src-line"><a name="a147"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;$modelTarget*&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;Name&nbsp;of&nbsp;Model&nbsp;on&nbsp;the&nbsp;RIGHT&nbsp;side&nbsp;of&nbsp;the&nbsp;relationship</span></div></li>
<li><div class="src-line"><a name="a148"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;$cardinality*&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;The&nbsp;cardinality&nbsp;of&nbsp;the&nbsp;relationship&nbsp;(see&nbsp;constants)</span></div></li>
<li><div class="src-line"><a name="a149"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;$modelLink&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;Name&nbsp;of&nbsp;Model&nbsp;that&nbsp;links&nbsp;source&nbsp;and&nbsp;target,&nbsp;if&nbsp;the&nbsp;cardinality&nbsp;is&nbsp;M:M</span></div></li>
<li><div class="src-line"><a name="a150"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;$reference&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;Custom&nbsp;reference&nbsp;for&nbsp;this&nbsp;relationship&nbsp;(defaults&nbsp;to&nbsp;self::REF_DEFAULT)</span></div></li>
<li><div class="src-line"><a name="a151"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;$limit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;For&nbsp;1:M&nbsp;relationships&nbsp;you&nbsp;can&nbsp;define&nbsp;a&nbsp;limit&nbsp;for&nbsp;M&nbsp;(for&nbsp;example,&nbsp;a&nbsp;1:1&nbsp;relation&nbsp;is&nbsp;just&nbsp;a&nbsp;1:M&nbsp;with&nbsp;limit&nbsp;of&nbsp;1)</span></div></li>
<li><div class="src-line"><a name="a152"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;$nativeKey&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;Name&nbsp;of&nbsp;the&nbsp;field&nbsp;used&nbsp;by&nbsp;the&nbsp;Model&nbsp;in&nbsp;the&nbsp;LEFT&nbsp;side&nbsp;of&nbsp;the&nbsp;relationship</span></div></li>
<li><div class="src-line"><a name="a153"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;$foreignKey&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;Name&nbsp;of&nbsp;the&nbsp;field&nbsp;used&nbsp;by&nbsp;the&nbsp;Model&nbsp;in&nbsp;the&nbsp;RIGHT&nbsp;side&nbsp;of&nbsp;teh&nbsp;relationship</span></div></li>
<li><div class="src-line"><a name="a154"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;$options&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;List&nbsp;of&nbsp;options&nbsp;to&nbsp;be&nbsp;set&nbsp;on&nbsp;this&nbsp;relationship&nbsp;(see&nbsp;below)</span></div></li>
<li><div class="src-line"><a name="a155"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a156"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Creates&nbsp;a&nbsp;new&nbsp;ModelRelation&nbsp;instance.</span></div></li>
<li><div class="src-line"><a name="a157"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;The&nbsp;possible&nbsp;options&nbsp;that&nbsp;can&nbsp;be&nbsp;set&nbsp;are:</span></div></li>
<li><div class="src-line"><a name="a158"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;nocascade&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;Prevents&nbsp;Models&nbsp;on&nbsp;the&nbsp;&quot;M&quot;&nbsp;side&nbsp;of&nbsp;a&nbsp;&quot;1:M&quot;&nbsp;relationship&nbsp;being&nbsp;deleted&nbsp;when&nbsp;the&nbsp;&quot;1&quot;&nbsp;side&nbsp;is&nbsp;deleted.</span></div></li>
<li><div class="src-line"><a name="a159"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;nocascadedelete&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;Prevents&nbsp;Models&nbsp;on&nbsp;the&nbsp;&quot;M&quot;&nbsp;side&nbsp;of&nbsp;a&nbsp;&quot;1:M&quot;&nbsp;relationship&nbsp;being&nbsp;deleted&nbsp;when&nbsp;the&nbsp;&quot;1&quot;&nbsp;side&nbsp;is&nbsp;deleted.</span></div></li>
<li><div class="src-line"><a name="a160"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;nocascadesave&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;Prevents&nbsp;Models&nbsp;on&nbsp;the&nbsp;&quot;M&quot;&nbsp;side&nbsp;of&nbsp;a&nbsp;&quot;1:M&quot;&nbsp;relationship&nbsp;being&nbsp;saved&nbsp;when&nbsp;the&nbsp;&quot;1&quot;&nbsp;side&nbsp;is&nbsp;saved.</span></div></li>
<li><div class="src-line"><a name="a161"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a162"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;TODO:&nbsp;Remove&nbsp;support&nbsp;for&nbsp;&quot;nocascade&quot;&nbsp;and&nbsp;replace&nbsp;with&nbsp;&quot;nocascadedelete&quot;&nbsp;-&nbsp;need&nbsp;to&nbsp;change&nbsp;all&nbsp;existing&nbsp;applications&nbsp;that&nbsp;use&nbsp;this.</span></div></li>
<li><div class="src-line"><a name="a163"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a164"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">private&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#method__construct">__construct</a><span class="src-sym">(</span><span class="src-var">$params</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a165"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a166"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Extract&nbsp;params</span></div></li>
<li><div class="src-line"><a name="a167"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.php.net/extract">extract</a><span class="src-sym">(</span><span class="src-var">$params</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a168"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$modelSource</span><span class="src-sym">)&nbsp;</span>||&nbsp;<span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$modelTarget</span><span class="src-sym">)&nbsp;</span>||&nbsp;<span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$cardinality</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a169"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;<span class="src-key">new&nbsp;</span><span class="src-id"><a href="../Buan/Exception.html">Exception</a></span><span class="src-sym">(</span><span class="src-str">'Required&nbsp;parameters&nbsp;not&nbsp;defined&nbsp;for&nbsp;this&nbsp;Model&nbsp;Relationship.'</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a170"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a171"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a172"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Convert&nbsp;a&nbsp;&quot;1:1&quot;&nbsp;relationship&nbsp;to&nbsp;&quot;1:M,1&quot;</span></div></li>
<li><div class="src-line"><a name="a173"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$cardinality</span>==<span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">::</span><span class="src-id">ONE_TO_ONE</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a174"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$cardinality&nbsp;</span>=&nbsp;<span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">::</span><span class="src-id">ONE_TO_MANY</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a175"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$limit&nbsp;</span>=&nbsp;<span class="src-num">1</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a176"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a177"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a178"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Set&nbsp;attributes</span></div></li>
<li><div class="src-line"><a name="a179"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#var$modelSource">modelSource</a>&nbsp;=&nbsp;<span class="src-var">$modelSource</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a180"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#var$modelTarget">modelTarget</a>&nbsp;=&nbsp;<span class="src-var">$modelTarget</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a181"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#var$modelLink">modelLink</a>&nbsp;=&nbsp;isset<span class="src-sym">(</span><span class="src-var">$modelLink</span><span class="src-sym">)&nbsp;</span>?&nbsp;<span class="src-var">$modelLink&nbsp;</span>:&nbsp;<span class="src-id">NULL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a182"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#var$reference">reference</a>&nbsp;=&nbsp;isset<span class="src-sym">(</span><span class="src-var">$reference</span><span class="src-sym">)&nbsp;</span>?&nbsp;<span class="src-var">$reference&nbsp;</span>:&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">REF_DEFAULT</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a183"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#var$cardinality">cardinality</a>&nbsp;=&nbsp;<span class="src-var">$cardinality</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a184"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#var$limit">limit</a>&nbsp;=&nbsp;<span class="src-var">$cardinality</span>==<span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">::</span><span class="src-id">ONE_TO_MANY&nbsp;</span>?&nbsp;<span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-var">$limit</span><span class="src-sym">)&nbsp;</span>?&nbsp;(int)<span class="src-var">$limit&nbsp;</span>:&nbsp;<span class="src-id">NULL</span><span class="src-sym">)&nbsp;</span>:&nbsp;<span class="src-id">NULL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a185"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#var$nativeKey">nativeKey</a>&nbsp;=&nbsp;<span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$nativeKey</span><span class="src-sym">)&nbsp;</span>?&nbsp;<span class="src-sym">(</span><span class="src-var">$cardinality</span>==<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">MANY_TO_ONE&nbsp;</span>?&nbsp;<span class="src-id"><a href="../Buan/Inflector.html">Inflector</a></span><span class="src-sym">::</span><a href="../Buan/Inflector.html#methodmodelName_dbTableName">modelName_dbTableName</a><span class="src-sym">(</span><span class="src-var">$modelTarget</span><span class="src-sym">)</span>.<span class="src-str">'_id'&nbsp;</span>:&nbsp;<span class="src-str">'id'</span><span class="src-sym">)&nbsp;</span>:&nbsp;<span class="src-var">$nativeKey</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a186"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#var$foreignKey">foreignKey</a>&nbsp;=&nbsp;<span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$foreignKey</span><span class="src-sym">)&nbsp;</span>?&nbsp;<span class="src-sym">(</span><span class="src-var">$cardinality</span>==<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">ONE_TO_MANY&nbsp;</span>?&nbsp;<span class="src-id"><a href="../Buan/Inflector.html">Inflector</a></span><span class="src-sym">::</span><a href="../Buan/Inflector.html#methodmodelName_dbTableName">modelName_dbTableName</a><span class="src-sym">(</span><span class="src-var">$modelSource</span><span class="src-sym">)</span>.<span class="src-str">'_id'&nbsp;</span>:&nbsp;<span class="src-str">'id'</span><span class="src-sym">)&nbsp;</span>:&nbsp;<span class="src-var">$foreignKey</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a187"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#var$options">options</a>&nbsp;=&nbsp;<span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-var">$options</span><span class="src-sym">)&nbsp;</span>?&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span>:&nbsp;<span class="src-var">$options</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a188"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a189"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Determine&nbsp;if&nbsp;this&nbsp;is&nbsp;a&nbsp;recursive&nbsp;relationship</span></div></li>
<li><div class="src-line"><a name="a190"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#var$isRecursive">isRecursive</a>&nbsp;=&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#var$modelSource">modelSource</a>==<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#var$modelTarget">modelTarget</a>&nbsp;?&nbsp;<span class="src-id">TRUE&nbsp;</span>:&nbsp;<span class="src-id">FALSE</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a191"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a192"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Warn&nbsp;is&nbsp;a&nbsp;M:M&nbsp;relationship&nbsp;is&nbsp;missing&nbsp;a&nbsp;linking&nbsp;Model</span></div></li>
<li><div class="src-line"><a name="a193"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#var$cardinality">cardinality</a>==<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">MANY_TO_MANY&nbsp;</span>&amp;&amp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#var$modelLink">modelLink</a>===<span class="src-id">NULL</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a194"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id"><a href="../Buan/SystemLog.html">SystemLog</a></span><span class="src-sym">::</span><a href="../Buan/SystemLog.html#methodadd">add</a><span class="src-sym">(</span><span class="src-str">'A&nbsp;M:M&nbsp;relationship&nbsp;is&nbsp;missing&nbsp;a&nbsp;linking&nbsp;Model&nbsp;in&nbsp;ModelRelation.'</span><span class="src-sym">,&nbsp;</span><span class="src-id"><a href="../Buan/SystemLog.html">SystemLog</a></span><span class="src-sym">::</span><span class="src-id">WARNING</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a195"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a196"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a197"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a198"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a199"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;void&nbsp;define(&nbsp;string&nbsp;$relationship,&nbsp;[string&nbsp;$options,&nbsp;[string&nbsp;$relationRef,&nbsp;[string&nbsp;$manyToManyPartial]]]&nbsp;)</span></div></li>
<li><div class="src-line"><a name="a200"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;$relationship&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;The&nbsp;relationship&nbsp;definition&nbsp;between&nbsp;2&nbsp;or&nbsp;more&nbsp;Models</span></div></li>
<li><div class="src-line"><a name="a201"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;$options&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;A&nbsp;comma-separated&nbsp;list&nbsp;of&nbsp;options&nbsp;to&nbsp;set&nbsp;on&nbsp;this&nbsp;relationship</span></div></li>
<li><div class="src-line"><a name="a202"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;$relationRef&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;String&nbsp;to&nbsp;identify&nbsp;the&nbsp;particulat&nbsp;relationship&nbsp;between&nbsp;source&nbsp;and&nbsp;target&nbsp;Models</span></div></li>
<li><div class="src-line"><a name="a203"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;$manyToManyPartial&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;Name&nbsp;of&nbsp;the&nbsp;linking&nbsp;Model&nbsp;that&nbsp;joins&nbsp;source&nbsp;and&nbsp;target&nbsp;in&nbsp;a&nbsp;M:M&nbsp;relationship&nbsp;(INTERNAL&nbsp;USE&nbsp;ONLY)</span></div></li>
<li><div class="src-line"><a name="a204"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a205"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Parses&nbsp;the&nbsp;given&nbsp;definition&nbsp;into&nbsp;several&nbsp;ModelRelation&nbsp;objects&nbsp;which,&nbsp;when&nbsp;combined&nbsp;with</span></div></li>
<li><div class="src-line"><a name="a206"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;all&nbsp;other&nbsp;ModelRelations,&nbsp;starts&nbsp;to&nbsp;build&nbsp;a&nbsp;comprehensive&nbsp;relationship&nbsp;mapping.</span></div></li>
<li><div class="src-line"><a name="a207"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;$relationship&nbsp;is&nbsp;in&nbsp;the&nbsp;form:</span></div></li>
<li><div class="src-line"><a name="a208"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ModelA[.nativeKey](cardinalityA,[limitA]):ModelB[.foreignKey](cardinalityB,[limitB])</span></div></li>
<li><div class="src-line"><a name="a209"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;or&nbsp;&nbsp;&nbsp;&nbsp;ModelA[.nativeKey](cardinalityA,[limitA]):ModelAB[.foreignKeyA][.foreignKeyB](cardinalityB,[limitB]):ModelB[.nativeKey](cardinalityB,[limitB])</span></div></li>
<li><div class="src-line"><a name="a210"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a211"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;eg.&nbsp;&nbsp;&nbsp;&nbsp;Blog(1):BlogEntry(M)</span></div></li>
<li><div class="src-line"><a name="a212"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;eg.&nbsp;&nbsp;&nbsp;&nbsp;Book(1):BookAuthor(M):Author(1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;here,&nbsp;&quot;BookAuthor&quot;&nbsp;is&nbsp;a&nbsp;Model&nbsp;that&nbsp;links&nbsp;two&nbsp;other&nbsp;Models,&nbsp;thus&nbsp;creating&nbsp;a&nbsp;M:M&nbsp;relationship</span></div></li>
<li><div class="src-line"><a name="a213"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;eg.&nbsp;&nbsp;&nbsp;&nbsp;Book(M):Author(M)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;This&nbsp;is&nbsp;a&nbsp;shortcut&nbsp;for&nbsp;the&nbsp;preceding&nbsp;definition.&nbsp;The&nbsp;system&nbsp;will&nbsp;assume&nbsp;linking&nbsp;table&nbsp;is&nbsp;&quot;BookAuthor&quot;</span></div></li>
<li><div class="src-line"><a name="a214"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;eg.&nbsp;&nbsp;&nbsp;&nbsp;Husband(1):Wife(1)</span></div></li>
<li><div class="src-line"><a name="a215"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;eg.&nbsp;&nbsp;&nbsp;&nbsp;Husband(1):Wife(M,1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;This&nbsp;is&nbsp;an&nbsp;alternative&nbsp;way&nbsp;of&nbsp;writing&nbsp;the&nbsp;preceding&nbsp;definition</span></div></li>
<li><div class="src-line"><a name="a216"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;eg.&nbsp;&nbsp;&nbsp;&nbsp;Person.id(1):Hobby.person_id(M)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;This&nbsp;shows&nbsp;the&nbsp;optional&nbsp;ability&nbsp;to&nbsp;define&nbsp;custom&nbsp;native&nbsp;and&nbsp;foreign-keys&nbsp;in&nbsp;a&nbsp;relationship</span></div></li>
<li><div class="src-line"><a name="a217"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;eg.&nbsp;&nbsp;&nbsp;&nbsp;Book(1):BookAuthor.book_id.author_id(M):Author(1)&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Note&nbsp;the&nbsp;double&nbsp;foreign-key&nbsp;in&nbsp;this&nbsp;special&nbsp;defintion&nbsp;type</span></div></li>
<li><div class="src-line"><a name="a218"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a219"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;The&nbsp;$relationRef&nbsp;parameter&nbsp;is&nbsp;only&nbsp;required&nbsp;if&nbsp;you&nbsp;are&nbsp;defining&nbsp;the&nbsp;same&nbsp;relationship&nbsp;several&nbsp;times,&nbsp;but</span></div></li>
<li><div class="src-line"><a name="a220"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;on&nbsp;different&nbsp;table&nbsp;columns.&nbsp;For&nbsp;example:</span></div></li>
<li><div class="src-line"><a name="a221"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User(1):Bug.reporter_id(M)&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;Could&nbsp;use,&nbsp;for&nbsp;example,&nbsp;a&nbsp;$relationRef&nbsp;of&nbsp;&quot;reporter&quot;</span></div></li>
<li><div class="src-line"><a name="a222"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User(1):Bug.assigned_id(M)&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;Could&nbsp;use,&nbsp;for&nbsp;example,&nbsp;a&nbsp;$relationRef&nbsp;of&nbsp;&quot;assigned&quot;</span></div></li>
<li><div class="src-line"><a name="a223"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a224"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Below&nbsp;are&nbsp;listed&nbsp;the&nbsp;methods&nbsp;for&nbsp;defining&nbsp;different&nbsp;relationshsips&nbsp;...</span></div></li>
<li><div class="src-line"><a name="a225"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;1:M</span></div></li>
<li><div class="src-line"><a name="a226"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Blog(1):BlogEntry(M)</span></div></li>
<li><div class="src-line"><a name="a227"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Husband(1):Wife(1)</span></div></li>
<li><div class="src-line"><a name="a228"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Husband(1):Wife(M,1)&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;Same&nbsp;as&nbsp;previous&nbsp;definition</span></div></li>
<li><div class="src-line"><a name="a229"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a230"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;M:M</span></div></li>
<li><div class="src-line"><a name="a231"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Book(1):BookAuthor(M):Author(1)&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;BookAuthor&nbsp;is&nbsp;the&nbsp;&quot;link&nbsp;model&quot;&nbsp;between&nbsp;Books&nbsp;and&nbsp;Authors</span></div></li>
<li><div class="src-line"><a name="a232"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a233"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;M:M&nbsp;recursive</span></div></li>
<li><div class="src-line"><a name="a234"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Person(1):Friend.fk1_id.fk2_id(M):Person(1)&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;You&nbsp;MUST&nbsp;define&nbsp;the&nbsp;foreign</span></div></li>
<li><div class="src-line"><a name="a235"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;keys&nbsp;used&nbsp;in&nbsp;the&nbsp;link&nbsp;model&nbsp;otherwise&nbsp;the&nbsp;system&nbsp;assumes&nbsp;they&nbsp;are&nbsp;both</span></div></li>
<li><div class="src-line"><a name="a236"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the&nbsp;same&nbsp;(person_id&nbsp;in&nbsp;this&nbsp;example)&nbsp;which&nbsp;is&nbsp;no&nbsp;help&nbsp;at&nbsp;all!</span></div></li>
<li><div class="src-line"><a name="a237"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a238"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">static&nbsp;</span><span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methoddefine">define</a><span class="src-sym">(</span><span class="src-var">$relationship</span><span class="src-sym">,&nbsp;</span><span class="src-var">$options</span>=<span class="src-id">NULL</span><span class="src-sym">,&nbsp;</span><span class="src-var">$relationRef</span>=<span class="src-id">NULL</span><span class="src-sym">,&nbsp;</span><span class="src-var">$manyToManyPartial</span>=<span class="src-id">NULL</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a239"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a240"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Keep&nbsp;track&nbsp;of&nbsp;relationships&nbsp;that&nbsp;have&nbsp;already&nbsp;previously&nbsp;been&nbsp;processed.</span></div></li>
<li><div class="src-line"><a name="a241"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Recursion&nbsp;can&nbsp;occur&nbsp;when&nbsp;defining&nbsp;M:M&nbsp;relationships,&nbsp;so&nbsp;this&nbsp;will&nbsp;prevent&nbsp;system&nbsp;hang-ups.</span></div></li>
<li><div class="src-line"><a name="a242"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">static&nbsp;</span><span class="src-var">$processedRelationships&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a243"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">in_array</span><span class="src-sym">(</span><span class="src-var">$relationship</span><span class="src-sym">,&nbsp;</span><span class="src-var">$processedRelationships</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a244"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-id">NULL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a245"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a246"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$processedRelationships</span><span class="src-sym">[</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-var">$relationship</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a247"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a248"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Vars</span></div></li>
<li><div class="src-line"><a name="a249"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$relationRef</span>===<span class="src-id">NULL</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a250"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$relationRef&nbsp;</span>=&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">REF_DEFAULT</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a251"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a252"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a253"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;If&nbsp;more&nbsp;than&nbsp;one&nbsp;relationship&nbsp;is&nbsp;being&nbsp;defined&nbsp;here&nbsp;(ie.&nbsp;1:M:1),&nbsp;break&nbsp;it&nbsp;down&nbsp;into</span></div></li>
<li><div class="src-line"><a name="a254"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;single&nbsp;relationships&nbsp;and&nbsp;parse&nbsp;each&nbsp;one&nbsp;separately.</span></div></li>
<li><div class="src-line"><a name="a255"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Also,&nbsp;the&nbsp;resulting&nbsp;M:M&nbsp;relationship&nbsp;is&nbsp;defined.</span></div></li>
<li><div class="src-line"><a name="a256"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><a href="http://www.php.net/substr_count">substr_count</a><span class="src-sym">(</span><span class="src-var">$relationship</span><span class="src-sym">,&nbsp;</span><span class="src-str">&quot;:&quot;</span><span class="src-sym">)</span>&gt;<span class="src-num">1</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a257"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a258"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Extract&nbsp;components</span></div></li>
<li><div class="src-line"><a name="a259"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$components&nbsp;</span>=&nbsp;<a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">&quot;:&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$relationship</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a260"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$mSource&nbsp;</span>=&nbsp;<a href="http://www.php.net/preg_replace">preg_replace</a><span class="src-sym">(</span><span class="src-str">&quot;/\(.+$/&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-str">&quot;&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$components</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a261"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$mLink&nbsp;</span>=&nbsp;<a href="http://www.php.net/preg_replace">preg_replace</a><span class="src-sym">(</span><span class="src-str">&quot;/\(.+$/&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-str">&quot;&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$components</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a262"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$mTarget&nbsp;</span>=&nbsp;<a href="http://www.php.net/preg_replace">preg_replace</a><span class="src-sym">(</span><span class="src-str">&quot;/\(.+$/&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-str">&quot;&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$components</span><span class="src-sym">[</span><span class="src-num">2</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a263"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$mSourceKey&nbsp;</span>=&nbsp;<span class="src-var">$mTargetKey&nbsp;</span>=&nbsp;<span class="src-id">NULL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a264"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$mLinkSourceKey&nbsp;</span>=&nbsp;<span class="src-id"><a href="../Buan/Inflector.html">Inflector</a></span><span class="src-sym">::</span><a href="../Buan/Inflector.html#methodmodelName_dbTableName">modelName_dbTableName</a><span class="src-sym">(</span><span class="src-var">$mSource</span><span class="src-sym">)</span>.<span class="src-str">'_id'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a265"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$mLinkTargetKey&nbsp;</span>=&nbsp;<span class="src-id"><a href="../Buan/Inflector.html">Inflector</a></span><span class="src-sym">::</span><a href="../Buan/Inflector.html#methodmodelName_dbTableName">modelName_dbTableName</a><span class="src-sym">(</span><span class="src-var">$mTarget</span><span class="src-sym">)</span>.<span class="src-str">'_id'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a266"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><a href="http://www.php.net/strpos">strpos</a><span class="src-sym">(</span><span class="src-var">$mSource</span><span class="src-sym">,&nbsp;</span><span class="src-str">&quot;.&quot;</span><span class="src-sym">)</span>!==<span class="src-id">FALSE</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a267"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list<span class="src-sym">(</span><span class="src-var">$mSource</span><span class="src-sym">,</span><span class="src-var">$mSourceKey</span><span class="src-sym">)&nbsp;</span>=&nbsp;<a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">&quot;.&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$mSource</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a268"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a269"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><a href="http://www.php.net/strpos">strpos</a><span class="src-sym">(</span><span class="src-var">$mTarget</span><span class="src-sym">,&nbsp;</span><span class="src-str">&quot;.&quot;</span><span class="src-sym">)</span>!==<span class="src-id">FALSE</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a270"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list<span class="src-sym">(</span><span class="src-var">$mTarget</span><span class="src-sym">,</span><span class="src-var">$mTargetKey</span><span class="src-sym">)&nbsp;</span>=&nbsp;<a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">&quot;.&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$mTarget</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a271"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a272"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><a href="http://www.php.net/strpos">strpos</a><span class="src-sym">(</span><span class="src-var">$mLink</span><span class="src-sym">,&nbsp;</span><span class="src-str">&quot;.&quot;</span><span class="src-sym">)</span>!==<span class="src-id">FALSE</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a273"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list<span class="src-sym">(</span><span class="src-var">$mLink</span><span class="src-sym">,</span><span class="src-var">$mLinkSourceKey</span><span class="src-sym">,</span><span class="src-var">$mLinkTargetKey</span><span class="src-sym">)&nbsp;</span>=&nbsp;<a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">&quot;.&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$mLink</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a274"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a275"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a276"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Define&nbsp;the&nbsp;resulting&nbsp;M:M&nbsp;relationship</span></div></li>
<li><div class="src-line"><a name="a277"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$mSource</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$mTarget</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$relationRef</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">new&nbsp;</span><span class="src-id">ModelRelation</span><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span></div></li>
<li><div class="src-line"><a name="a278"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelSource'</span>=&gt;<span class="src-var">$mSource</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a279"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelTarget'</span>=&gt;<span class="src-var">$mTarget</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a280"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'cardinality'</span>=&gt;<span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">::</span><span class="src-id">MANY_TO_MANY</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a281"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelLink'</span>=&gt;<span class="src-var">$mLink</span></div></li>
<li><div class="src-line"><a name="a282"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a283"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$mSource</span>!=<span class="src-var">$mTarget</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a284"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$mTarget</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$mSource</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$relationRef</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">new&nbsp;</span><span class="src-id">ModelRelation</span><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span></div></li>
<li><div class="src-line"><a name="a285"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelSource'</span>=&gt;<span class="src-var">$mTarget</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a286"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelTarget'</span>=&gt;<span class="src-var">$mSource</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a287"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'cardinality'</span>=&gt;<span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">::</span><span class="src-id">MANY_TO_MANY</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a288"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelLink'</span>=&gt;<span class="src-var">$mLink</span></div></li>
<li><div class="src-line"><a name="a289"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a290"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a291"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">define</span><span class="src-sym">(</span><span class="src-str">&quot;</span>{<span class="src-var">$components</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]<span class="src-str"></span><span class="src-sym">}</span>:{<span class="src-var">$mLink</span><span class="src-sym">}</span>.{<span class="src-var">$mLinkSourceKey</span><span class="src-sym">}</span>(M)</span><span class="src-str">&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$options</span><span class="src-sym">,&nbsp;</span><span class="src-var">$relationRef</span><span class="src-sym">,&nbsp;</span><span class="src-var">$mTarget</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a292"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">define</span><span class="src-sym">(</span><span class="src-str">&quot;</span>{<span class="src-var">$mLink<span class="src-str"></span><span class="src-sym">}</span>.{<span class="src-var">$mLinkSourceKey</span><span class="src-sym">}</span>(M):{<span class="src-var">$components</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">}</span></span><span class="src-str">&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$options</span><span class="src-sym">,&nbsp;</span><span class="src-var">$relationRef</span><span class="src-sym">,&nbsp;</span><span class="src-var">$mTarget</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a293"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">define</span><span class="src-sym">(</span><span class="src-str">&quot;</span>{<span class="src-var">$mLink<span class="src-str"></span><span class="src-sym">}</span>.{<span class="src-var">$mLinkTargetKey</span><span class="src-sym">}</span>(M):{<span class="src-var">$components</span><span class="src-sym">[</span><span class="src-num">2</span><span class="src-sym">]</span><span class="src-sym">}</span></span><span class="src-str">&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$options</span><span class="src-sym">,&nbsp;</span><span class="src-var">$relationRef</span><span class="src-sym">,&nbsp;</span><span class="src-var">$mSource</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a294"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">define</span><span class="src-sym">(</span><span class="src-str">&quot;</span>{<span class="src-var">$components</span><span class="src-sym">[</span><span class="src-num">2</span><span class="src-sym">]<span class="src-str"></span><span class="src-sym">}</span>{<span class="src-var">$mLink</span><span class="src-sym">}</span>.{<span class="src-var">$mLinkTargetKey</span><span class="src-sym">}</span>(M)</span><span class="src-str">&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$options</span><span class="src-sym">,&nbsp;</span><span class="src-var">$relationRef</span><span class="src-sym">,&nbsp;</span><span class="src-var">$mSource</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a295"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a296"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">else&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a297"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$mSource</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$mTarget</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">REF_CHILD</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">new&nbsp;</span><span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span></div></li>
<li><div class="src-line"><a name="a298"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelSource'</span>=&gt;<span class="src-var">$mSource</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a299"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelTarget'</span>=&gt;<span class="src-var">$mTarget</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a300"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'cardinality'</span>=&gt;<span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">::</span><span class="src-id">MANY_TO_MANY</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a301"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelLink'</span>=&gt;<span class="src-var">$mLink</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a302"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'reference'</span>=&gt;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">REF_CHILD</span></div></li>
<li><div class="src-line"><a name="a303"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a304"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a305"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">define</span><span class="src-sym">(</span><span class="src-str">&quot;</span>{<span class="src-var">$components</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]<span class="src-str"></span><span class="src-sym">}</span>:{<span class="src-var">$mLink</span><span class="src-sym">}</span>.{<span class="src-var">$mLinkSourceKey</span><span class="src-sym">}</span>(M)</span><span class="src-str">&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$options</span><span class="src-sym">,&nbsp;</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">REF_PARENT</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a306"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">define</span><span class="src-sym">(</span><span class="src-str">&quot;</span>{<span class="src-var">$mLink<span class="src-str"></span><span class="src-sym">}</span>.{<span class="src-var">$mLinkTargetKey</span><span class="src-sym">}</span>(M):{<span class="src-var">$components</span><span class="src-sym">[</span><span class="src-num">2</span><span class="src-sym">]</span><span class="src-sym">}</span></span><span class="src-str">&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$options</span><span class="src-sym">,&nbsp;</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">REF_CHILD</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a307"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a308"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a309"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">////&nbsp;Define&nbsp;the&nbsp;individual&nbsp;relationships,&nbsp;ie.&nbsp;1:M&nbsp;and&nbsp;M:1</span></div></li>
<li><div class="src-line"><a name="a310"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*if($mSource!=$mTarget)&nbsp;{</span></div></li>
<li><div class="src-line"><a name="a311"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self::define(&quot;{$components[0]}:{$mLink}.{$mLinkSourceKey}(M)&quot;,&nbsp;$options,&nbsp;$relationRef,&nbsp;$mTarget);</span></div></li>
<li><div class="src-line"><a name="a312"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self::define(&quot;{$mLink}.{$mLinkSourceKey}(M):{$components[0]}&quot;,&nbsp;$options,&nbsp;$relationRef,&nbsp;$mTarget);</span></div></li>
<li><div class="src-line"><a name="a313"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self::define(&quot;{$mLink}.{$mLinkTargetKey}(M):{$components[2]}&quot;,&nbsp;$options,&nbsp;$relationRef,&nbsp;$mSource);</span></div></li>
<li><div class="src-line"><a name="a314"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self::define(&quot;{$components[2]}{$mLink}.{$mLinkTargetKey}(M)&quot;,&nbsp;$options,&nbsp;$relationRef,&nbsp;$mSource);</span></div></li>
<li><div class="src-line"><a name="a315"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></div></li>
<li><div class="src-line"><a name="a316"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;{</span></div></li>
<li><div class="src-line"><a name="a317"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($mLinkSourceKey==$mLinkTargetKey)&nbsp;{</span></div></li>
<li><div class="src-line"><a name="a318"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$mLinkSourceKey&nbsp;=&nbsp;&quot;src_{$mLinkSourceKey}&quot;;</span></div></li>
<li><div class="src-line"><a name="a319"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$mLinkTargetKey&nbsp;=&nbsp;&quot;tgt_{$mLinkTargetKey}&quot;;</span></div></li>
<li><div class="src-line"><a name="a320"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></div></li>
<li><div class="src-line"><a name="a321"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//self::define(&quot;{$components[0]}:{$mLink}.{$mLinkSourceKey}(M)&quot;,&nbsp;$options,&nbsp;self::REF_PARENT);</span></div></li>
<li><div class="src-line"><a name="a322"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//self::define(&quot;{$mLink}.{$mLinkSourceKey}(M):{$components[0]}&quot;,&nbsp;$options,&nbsp;self::REF_PARENT);</span></div></li>
<li><div class="src-line"><a name="a323"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//self::define(&quot;{$mLink}.{$mLinkTargetKey}(M):{$components[2]}&quot;,&nbsp;$options,&nbsp;self::REF_CHILD);</span></div></li>
<li><div class="src-line"><a name="a324"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//self::define(&quot;{$components[2]}{$mLink}.{$mLinkTargetKey}(M)&quot;,&nbsp;$options,&nbsp;self::REF_CHILD);</span></div></li>
<li><div class="src-line"><a name="a325"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}*/</span></div></li>
<li><div class="src-line"><a name="a326"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a327"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Result</span></div></li>
<li><div class="src-line"><a name="a328"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-id">NULL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a329"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a330"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a331"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Extract&nbsp;components&nbsp;of&nbsp;the&nbsp;relationship&nbsp;into&nbsp;an&nbsp;ordered&nbsp;array</span></div></li>
<li><div class="src-line"><a name="a332"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.php.net/preg_match_all">preg_match_all</a><span class="src-sym">(</span><span class="src-str">&quot;/([^:]*?)\((.*?)\)/&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$relationship</span><span class="src-sym">,&nbsp;</span><span class="src-var">$m</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a333"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$m_all&nbsp;</span>=&nbsp;<span class="src-var">$m</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a334"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$m_model&nbsp;</span>=&nbsp;<span class="src-var">$m</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a335"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$m_card&nbsp;</span>=&nbsp;<span class="src-var">$m</span><span class="src-sym">[</span><span class="src-num">2</span><span class="src-sym">]</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a336"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$m_key&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-id">NULL</span><span class="src-sym">,&nbsp;</span><span class="src-id">NULL</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a337"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$limit&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-id">NULL</span><span class="src-sym">,&nbsp;</span><span class="src-id">NULL</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a338"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><a href="http://www.php.net/strpos">strpos</a><span class="src-sym">(</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">,&nbsp;</span><span class="src-str">&quot;.&quot;</span><span class="src-sym">)</span>!==<span class="src-id">FALSE</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a339"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list<span class="src-sym">(</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">,</span><span class="src-var">$m_key</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">)&nbsp;</span>=&nbsp;<a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">&quot;.&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a340"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a341"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><a href="http://www.php.net/strpos">strpos</a><span class="src-sym">(</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">,&nbsp;</span><span class="src-str">&quot;.&quot;</span><span class="src-sym">)</span>!==<span class="src-id">FALSE</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a342"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list<span class="src-sym">(</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">,</span><span class="src-var">$m_key</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">)&nbsp;</span>=&nbsp;<a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">&quot;.&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a343"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a344"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a345"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Create&nbsp;the&nbsp;ModelRelation&nbsp;instances</span></div></li>
<li><div class="src-line"><a name="a346"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-sym">!</span>isset<span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]]</span><span class="src-sym">[</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]]</span><span class="src-sym">[</span><span class="src-var">$relationRef</span><span class="src-sym">]</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a347"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a348"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Extract&nbsp;any&nbsp;limits&nbsp;imposed&nbsp;on&nbsp;the&nbsp;cardinality</span></div></li>
<li><div class="src-line"><a name="a349"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$m_card&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$k</span>=&gt;<span class="src-var">$v</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a350"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">strpos</span><span class="src-sym">(</span><span class="src-var">$v</span><span class="src-sym">,&nbsp;</span><span class="src-str">&quot;,&quot;</span><span class="src-sym">)</span>!==<span class="src-id">FALSE</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a351"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$limit</span><span class="src-sym">[</span><span class="src-var">$k</span><span class="src-sym">]&nbsp;</span>=&nbsp;(int)<a href="http://www.php.net/preg_replace">preg_replace</a><span class="src-sym">(</span><span class="src-str">&quot;/^.*?,([0-9]+)/&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-str">&quot;$1&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$v</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a352"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$m_card</span><span class="src-sym">[</span><span class="src-var">$k</span><span class="src-sym">]&nbsp;</span>=&nbsp;<a href="http://www.php.net/preg_replace">preg_replace</a><span class="src-sym">(</span><span class="src-str">&quot;/,.*/&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-str">&quot;&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$v</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a353"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a354"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a355"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a356"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Find&nbsp;the&nbsp;cardinality&nbsp;between&nbsp;the&nbsp;two&nbsp;Models</span></div></li>
<li><div class="src-line"><a name="a357"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$cardinalityMap&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span></div></li>
<li><div class="src-line"><a name="a358"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'1:M'</span>=&gt;<span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">::</span><span class="src-id">ONE_TO_MANY</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a359"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'M:1'</span>=&gt;<span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">::</span><span class="src-id">MANY_TO_ONE</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a360"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'M:M'</span>=&gt;<span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">::</span><span class="src-id">MANY_TO_MANY</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a361"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'1:1'</span>=&gt;<span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">::</span><span class="src-id">ONE_TO_ONE</span></div></li>
<li><div class="src-line"><a name="a362"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a363"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$cardinality&nbsp;</span>=&nbsp;<span class="src-var">$cardinalityMap</span><span class="src-sym">[</span><a href="http://www.php.net/strtoupper">strtoupper</a><span class="src-sym">(</span><a href="http://www.php.net/implode">implode</a><span class="src-sym">(</span><span class="src-str">&quot;:&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$m_card</span><span class="src-sym">))</span><span class="src-sym">]</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a364"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$revCardinality&nbsp;</span>=&nbsp;<span class="src-var">$cardinalityMap</span><span class="src-sym">[</span><a href="http://www.php.net/strtoupper">strtoupper</a><span class="src-sym">(</span><a href="http://www.php.net/implode">implode</a><span class="src-sym">(</span><span class="src-str">&quot;:&quot;</span><span class="src-sym">,&nbsp;</span><a href="http://www.php.net/array_reverse">array_reverse</a><span class="src-sym">(</span><span class="src-var">$m_card</span><span class="src-sym">)))</span><span class="src-sym">]</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a365"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a366"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;If&nbsp;a&nbsp;M:M&nbsp;cardinality&nbsp;is&nbsp;defined,&nbsp;we&nbsp;need&nbsp;to&nbsp;insert&nbsp;a&nbsp;linking&nbsp;table&nbsp;with&nbsp;an&nbsp;assumed&nbsp;name,</span></div></li>
<li><div class="src-line"><a name="a367"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;and&nbsp;then&nbsp;define&nbsp;the&nbsp;required&nbsp;1:M:1&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a368"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;We&nbsp;will&nbsp;assume&nbsp;that&nbsp;no&nbsp;keys&nbsp;have&nbsp;been&nbsp;defined&nbsp;in&nbsp;this&nbsp;M:M&nbsp;relationship,&nbsp;because&nbsp;it&nbsp;doesn't</span></div></li>
<li><div class="src-line"><a name="a369"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;make&nbsp;sense&nbsp;as&nbsp;the&nbsp;Models&nbsp;are&nbsp;not&nbsp;directly&nbsp;related.</span></div></li>
<li><div class="src-line"><a name="a370"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//$linkModel&nbsp;=&nbsp;NULL;</span></div></li>
<li><div class="src-line"><a name="a371"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$cardinality</span>==<span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">::</span><span class="src-id">MANY_TO_MANY</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a372"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$linkModel&nbsp;</span>=&nbsp;<span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span>.<span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a373"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$relation&nbsp;</span>=&nbsp;<span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span>.<span class="src-str">'(1):'</span>.<span class="src-var">$linkModel</span>.<span class="src-str">'(M):'</span>.<span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span>.<span class="src-str">'(1)'</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a374"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">define</span><span class="src-sym">(</span><span class="src-var">$relation</span><span class="src-sym">,&nbsp;</span><span class="src-var">$options</span><span class="src-sym">,&nbsp;</span><span class="src-var">$relationRef</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a375"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-id">NULL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a376"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a377"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a378"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;If&nbsp;a&nbsp;1:1&nbsp;relation&nbsp;is&nbsp;defined,&nbsp;change&nbsp;it&nbsp;to&nbsp;a&nbsp;1:M,1</span></div></li>
<li><div class="src-line"><a name="a379"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$cardinality</span>==<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">ONE_TO_ONE</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a380"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$cardinality&nbsp;</span>=&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">ONE_TO_MANY</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a381"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$revCardinality&nbsp;</span>=&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">MANY_TO_ONE</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a382"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$limit&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-num">1</span><span class="src-sym">,&nbsp;</span><span class="src-num">1</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a383"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a384"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a385"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;For&nbsp;recursive&nbsp;1:M&nbsp;relationships,&nbsp;make&nbsp;sure&nbsp;that&nbsp;the&nbsp;definition&nbsp;is&nbsp;1:M,&nbsp;not&nbsp;M:1</span></div></li>
<li><div class="src-line"><a name="a386"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span>==<span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]&nbsp;</span>&amp;&amp;&nbsp;<span class="src-var">$cardinality</span>==<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">MANY_TO_ONE</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a387"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$m_model&nbsp;</span>=&nbsp;<a href="http://www.php.net/array_reverse">array_reverse</a><span class="src-sym">(</span><span class="src-var">$m_model</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a388"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$cardinality&nbsp;</span>=&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">ONE_TO_MANY</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a389"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$revCardinality&nbsp;</span>=&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">MANY_TO_ONE</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a390"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$limit&nbsp;</span>=&nbsp;<a href="http://www.php.net/array_reverse">array_reverse</a><span class="src-sym">(</span><span class="src-var">$limit</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a391"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a392"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Create&nbsp;the&nbsp;&quot;M:1&quot;&nbsp;relationship&nbsp;here&nbsp;(ref:&nbsp;self::REF_CHILD)</span></div></li>
<li><div class="src-line"><a name="a393"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]]</span><span class="src-sym">[</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]]</span><span class="src-sym">[</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">REF_CHILD</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">new&nbsp;</span><span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span></div></li>
<li><div class="src-line"><a name="a394"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelSource'</span>=&gt;<span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a395"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelTarget'</span>=&gt;<span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a396"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'cardinality'</span>=&gt;<span class="src-var">$revCardinality</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a397"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelLink'</span>=&gt;<span class="src-var">$manyToManyPartial</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a398"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'reference'</span>=&gt;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">REF_CHILD</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a399"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'limit'</span>=&gt;<span class="src-var">$limit</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a400"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'nativeKey'</span>=&gt;<span class="src-var">$m_key</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a401"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'foreignKey'</span>=&gt;<span class="src-var">$m_key</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a402"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'options'</span>=&gt;<span class="src-var">$options</span></div></li>
<li><div class="src-line"><a name="a403"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a404"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a405"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">else&nbsp;</span><span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span>==<span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]&nbsp;</span>&amp;&amp;&nbsp;<span class="src-var">$cardinality</span>==<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">ONE_TO_MANY</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a406"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Create&nbsp;the&nbsp;&quot;M:1&quot;&nbsp;relationship&nbsp;here&nbsp;(ref:&nbsp;self::REF_CHILD)</span></div></li>
<li><div class="src-line"><a name="a407"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]]</span><span class="src-sym">[</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]]</span><span class="src-sym">[</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">REF_CHILD</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">new&nbsp;</span><span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span></div></li>
<li><div class="src-line"><a name="a408"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelSource'</span>=&gt;<span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a409"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelTarget'</span>=&gt;<span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a410"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'cardinality'</span>=&gt;<span class="src-var">$revCardinality</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a411"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelLink'</span>=&gt;<span class="src-var">$manyToManyPartial</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a412"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'reference'</span>=&gt;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">REF_CHILD</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a413"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'limit'</span>=&gt;<span class="src-var">$limit</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a414"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'nativeKey'</span>=&gt;<span class="src-var">$m_key</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a415"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'foreignKey'</span>=&gt;<span class="src-var">$m_key</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a416"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'options'</span>=&gt;<span class="src-var">$options</span></div></li>
<li><div class="src-line"><a name="a417"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a418"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a419"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a420"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Extract&nbsp;options</span></div></li>
<li><div class="src-line"><a name="a421"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$options&nbsp;</span>=&nbsp;<span class="src-var">$options</span>===<span class="src-id">NULL&nbsp;</span>?&nbsp;<span class="src-id">NULL&nbsp;</span>:&nbsp;<a href="http://www.php.net/explode">explode</a><span class="src-sym">(</span><span class="src-str">&quot;,&quot;</span><span class="src-sym">,&nbsp;</span><a href="http://www.php.net/strtolower">strtolower</a><span class="src-sym">(</span><span class="src-var">$options</span><span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a422"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a423"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Create&nbsp;relationships</span></div></li>
<li><div class="src-line"><a name="a424"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]]</span><span class="src-sym">[</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]]</span><span class="src-sym">[</span><span class="src-var">$relationRef</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">new&nbsp;</span><span class="src-id">ModelRelation</span><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span></div></li>
<li><div class="src-line"><a name="a425"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelSource'</span>=&gt;<span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a426"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelTarget'</span>=&gt;<span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a427"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'cardinality'</span>=&gt;<span class="src-var">$cardinality</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a428"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelLink'</span>=&gt;<span class="src-var">$manyToManyPartial</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a429"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'reference'</span>=&gt;<span class="src-var">$relationRef</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a430"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'limit'</span>=&gt;<span class="src-var">$limit</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a431"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'nativeKey'</span>=&gt;<span class="src-var">$m_key</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a432"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'foreignKey'</span>=&gt;<span class="src-var">$m_key</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a433"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'options'</span>=&gt;<span class="src-var">$options</span></div></li>
<li><div class="src-line"><a name="a434"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a435"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span>!=<span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]&nbsp;</span>&amp;&amp;&nbsp;<span class="src-var">$manyToManyPartial</span>===<span class="src-id">NULL</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a436"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]]</span><span class="src-sym">[</span><span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]]</span><span class="src-sym">[</span><span class="src-var">$relationRef</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">new&nbsp;</span><span class="src-id">ModelRelation</span><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span></div></li>
<li><div class="src-line"><a name="a437"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelSource'</span>=&gt;<span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a438"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelTarget'</span>=&gt;<span class="src-var">$m_model</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a439"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'cardinality'</span>=&gt;<span class="src-var">$revCardinality</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a440"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelLink'</span>=&gt;<span class="src-var">$manyToManyPartial</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a441"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'reference'</span>=&gt;<span class="src-var">$relationRef</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a442"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'limit'</span>=&gt;<span class="src-var">$limit</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a443"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'nativeKey'</span>=&gt;<span class="src-var">$m_key</span><span class="src-sym">[</span><span class="src-num">1</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a444"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'foreignKey'</span>=&gt;<span class="src-var">$m_key</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a445"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'options'</span>=&gt;<span class="src-var">$options</span></div></li>
<li><div class="src-line"><a name="a446"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a447"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a448"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a449"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a450"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a451"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a452"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;ModelRelation|array&nbsp;getRelation(&nbsp;string&nbsp;$modelSource,&nbsp;[string&nbsp;$modelTarget,&nbsp;[string&nbsp;$relationRef]]&nbsp;)</span></div></li>
<li><div class="src-line"><a name="a453"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;$modelSource&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;Name&nbsp;of&nbsp;the&nbsp;Model&nbsp;on&nbsp;the&nbsp;LEFT&nbsp;side&nbsp;of&nbsp;the&nbsp;relationship</span></div></li>
<li><div class="src-line"><a name="a454"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;$modelTarget&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;Name&nbsp;of&nbsp;the&nbsp;Model&nbsp;on&nbsp;the&nbsp;RIGHT&nbsp;side&nbsp;of&nbsp;the&nbsp;relationship</span></div></li>
<li><div class="src-line"><a name="a455"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;$relationRef&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;The&nbsp;specific&nbsp;relationship&nbsp;to&nbsp;return</span></div></li>
<li><div class="src-line"><a name="a456"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a457"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Finds&nbsp;and&nbsp;returns&nbsp;a&nbsp;ModelRelation&nbsp;that&nbsp;describes&nbsp;the&nbsp;relationship&nbsp;between&nbsp;the&nbsp;two&nbsp;given&nbsp;Models&nbsp;(or&nbsp;all&nbsp;other&nbsp;Models&nbsp;if</span></div></li>
<li><div class="src-line"><a name="a458"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;$modelTarget&nbsp;is&nbsp;not&nbsp;defined).</span></div></li>
<li><div class="src-line"><a name="a459"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a460"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;If&nbsp;you&nbsp;do&nbsp;not&nbsp;specify&nbsp;$relationRef&nbsp;and&nbsp;multiple&nbsp;relationships&nbsp;are&nbsp;available&nbsp;for&nbsp;a&nbsp;particular&nbsp;source/target&nbsp;Model&nbsp;pair,</span></div></li>
<li><div class="src-line"><a name="a461"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;then&nbsp;ALL&nbsp;relations&nbsp;will&nbsp;be&nbsp;returned&nbsp;as&nbsp;an&nbsp;array&nbsp;hash&nbsp;(index&nbsp;by&nbsp;relation&nbsp;reference).&nbsp;If&nbsp;neither&nbsp;$modelTarget&nbsp;or&nbsp;$relationRef</span></div></li>
<li><div class="src-line"><a name="a462"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;are&nbsp;specified&nbsp;then&nbsp;all&nbsp;relations&nbsp;will&nbsp;be&nbsp;returned&nbsp;in&nbsp;a&nbsp;1-dimensional&nbsp;array&nbsp;(no&nbsp;reference&nbsp;indexes).</span></div></li>
<li><div class="src-line"><a name="a463"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a464"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;You&nbsp;can&nbsp;enter&nbsp;two&nbsp;Models&nbsp;that&nbsp;are&nbsp;part&nbsp;of&nbsp;a&nbsp;M:M&nbsp;relationship&nbsp;and&nbsp;this&nbsp;function&nbsp;will&nbsp;attempt&nbsp;to&nbsp;find&nbsp;a&nbsp;Model&nbsp;that&nbsp;links&nbsp;those&nbsp;Models.</span></div></li>
<li><div class="src-line"><a name="a465"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;If&nbsp;none&nbsp;is&nbsp;found&nbsp;then&nbsp;it&nbsp;returns&nbsp;a&nbsp;ModelRelation&nbsp;instance&nbsp;with&nbsp;a&nbsp;cardinality&nbsp;of&nbsp;NONE.</span></div></li>
<li><div class="src-line"><a name="a466"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a467"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">static&nbsp;</span><span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodgetRelation">getRelation</a><span class="src-sym">(</span><span class="src-var">$modelSource</span><span class="src-sym">,&nbsp;</span><span class="src-var">$modelTarget</span>=<span class="src-id">NULL</span><span class="src-sym">,&nbsp;</span><span class="src-var">$relationRef</span>=<span class="src-id">NULL</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a468"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a469"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Pass&nbsp;back&nbsp;ALL&nbsp;relationships</span></div></li>
<li><div class="src-line"><a name="a470"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$modelTarget</span>===<span class="src-id">NULL</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a471"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$relations&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a472"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$relationMap&nbsp;</span>=&nbsp;isset<span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]</span><span class="src-sym">)&nbsp;</span>?&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]&nbsp;</span>:&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a473"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$relationMap&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$k</span>=&gt;<span class="src-var">$rel</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a474"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$rel&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$r</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a475"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$relations</span><span class="src-sym">[</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-var">$r</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a476"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a477"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">reset</span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$k</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a478"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a479"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$relations</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a480"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a481"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a482"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;First,&nbsp;check&nbsp;if&nbsp;we've&nbsp;got&nbsp;a&nbsp;direct&nbsp;relationship&nbsp;(works&nbsp;for&nbsp;1:1,&nbsp;1:M&nbsp;and&nbsp;M:1)</span></div></li>
<li><div class="src-line"><a name="a483"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$modelTarget</span><span class="src-sym">]</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a484"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$relationRef</span>===<span class="src-id">NULL</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a485"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$rel&nbsp;</span>=&nbsp;<a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$modelTarget</span><span class="src-sym">]</span><span class="src-sym">)</span>&gt;<span class="src-num">1&nbsp;</span>?&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$modelTarget</span><span class="src-sym">]&nbsp;</span>:&nbsp;<span class="src-id">current</span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$modelTarget</span><span class="src-sym">]</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a486"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$rel</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a487"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a488"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">else&nbsp;</span><span class="src-key">if</span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$modelTarget</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$relationRef</span><span class="src-sym">]</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a489"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$modelTarget</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$relationRef</span><span class="src-sym">]</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a490"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a491"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">else&nbsp;</span><span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$modelSource</span>!=<span class="src-var">$modelTarget</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a492"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id">SystemLog</span><span class="src-sym">::</span><span class="src-id">add</span><span class="src-sym">(</span><span class="src-str">&quot;</span><span class="src-str">No&nbsp;relationship&nbsp;with&nbsp;reference&nbsp;'{<span class="src-var">$relationRef</span><span class="src-sym">}</span>'&nbsp;has&nbsp;been&nbsp;defined&nbsp;for&nbsp;{<span class="src-var">$modelSource</span><span class="src-sym">}</span>:{<span class="src-var">$modelTarget</span><span class="src-sym">}</span></span><span class="src-str">&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-id"><a href="../Buan/SystemLog.html">SystemLog</a></span><span class="src-sym">::</span><span class="src-id">CORE</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a493"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-key">new&nbsp;</span><span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span></div></li>
<li><div class="src-line"><a name="a494"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelSource'</span>=&gt;<span class="src-var">$modelSource</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a495"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelTarget'</span>=&gt;<span class="src-var">$modelTarget</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a496"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'cardinality'</span>=&gt;<span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">::</span><span class="src-id">NONE</span></div></li>
<li><div class="src-line"><a name="a497"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a498"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a499"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a500"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a501"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Try&nbsp;to&nbsp;construct&nbsp;a&nbsp;M:M&nbsp;relationship&nbsp;</span></div></li>
<li><div class="src-line"><a name="a502"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a503"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$relationRef&nbsp;</span>=&nbsp;<span class="src-var">$relationRef</span>===<span class="src-id">NULL&nbsp;</span>?&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">REF_DEFAULT&nbsp;</span>:&nbsp;<span class="src-var">$relationRef</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a504"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$linkModel</span>=&gt;<span class="src-var">$relation</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a505"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$linkModel</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$modelTarget</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$relationRef</span><span class="src-sym">]</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a506"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$modelTarget</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$relationRef</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-key">new&nbsp;</span><span class="src-id">ModelRelation</span><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span></div></li>
<li><div class="src-line"><a name="a507"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelSource'</span>=&gt;<span class="src-var">$modelSource</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a508"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelTarget'</span>=&gt;<span class="src-var">$modelTarget</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a509"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'cardinality'</span>=&gt;<span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">::</span><span class="src-id">MANY_TO_MANY</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a510"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelLink'</span>=&gt;<span class="src-var">$linkModel</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a511"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'reference'</span>=&gt;<span class="src-var">$relationRef</span></div></li>
<li><div class="src-line"><a name="a512"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a513"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a514"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a515"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a516"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a517"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;If&nbsp;all&nbsp;else&nbsp;fails,&nbsp;return&nbsp;a&nbsp;ModelRelation&nbsp;with&nbsp;NONE&nbsp;cardinality</span></div></li>
<li><div class="src-line"><a name="a518"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-id"><a href="../Buan/SystemLog.html">SystemLog</a></span><span class="src-sym">::</span><a href="../Buan/SystemLog.html#methodadd">add</a><span class="src-sym">(</span><span class="src-str">&quot;</span><span class="src-str">No&nbsp;relationship&nbsp;has&nbsp;been&nbsp;defined&nbsp;for&nbsp;{<span class="src-var">$modelSource</span><span class="src-sym">}</span>:{<span class="src-var">$modelTarget</span><span class="src-sym">}</span></span><span class="src-str">&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-id"><a href="../Buan/SystemLog.html">SystemLog</a></span><span class="src-sym">::</span><span class="src-id">CORE</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a519"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-key">new&nbsp;</span><span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span></div></li>
<li><div class="src-line"><a name="a520"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelSource'</span>=&gt;<span class="src-var">$modelSource</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a521"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelTarget'</span>=&gt;<span class="src-var">$modelTarget</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a522"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'cardinality'</span>=&gt;<span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">::</span><span class="src-id">NONE</span></div></li>
<li><div class="src-line"><a name="a523"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a524"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a525"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a526"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">static&nbsp;</span><span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodgetRelationsByCardinality">getRelationsByCardinality</a><span class="src-sym">(</span><span class="src-var">$modelSource</span><span class="src-sym">,&nbsp;</span><span class="src-var">$cardinality</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a527"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$relations&nbsp;</span>=&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a528"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$relationMap&nbsp;</span>=&nbsp;isset<span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]</span><span class="src-sym">)&nbsp;</span>?&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]&nbsp;</span>:&nbsp;<span class="src-key">array</span><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a529"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$relationMap&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$rel</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a530"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$rel</span><span class="src-sym">-&gt;</span><span class="src-id">getCardinality</span><span class="src-sym">(</span><span class="src-sym">)</span>==<span class="src-var">$cardinality</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a531"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$relations</span><span class="src-sym">[</span><span class="src-sym">]&nbsp;</span>=&nbsp;<span class="src-var">$rel</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a532"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a533"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a534"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$relations</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a535"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a536"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a537"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a538"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;string&nbsp;getSourceModel()</span></div></li>
<li><div class="src-line"><a name="a539"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a540"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Returns&nbsp;$this-&gt;modelSource</span></div></li>
<li><div class="src-line"><a name="a541"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a542"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodgetSourceModel">getSourceModel</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a543"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a544"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Result</span></div></li>
<li><div class="src-line"><a name="a545"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$modelSource">modelSource</a></span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a546"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a547"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a548"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a549"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;string&nbsp;getTargetModel()</span></div></li>
<li><div class="src-line"><a name="a550"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a551"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Returns&nbsp;$this-&gt;modelTarget</span></div></li>
<li><div class="src-line"><a name="a552"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a553"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodgetTargetModel">getTargetModel</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a554"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a555"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Result</span></div></li>
<li><div class="src-line"><a name="a556"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$modelTarget">modelTarget</a></span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a557"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a558"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a559"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a560"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;string&nbsp;getLinkModel()</span></div></li>
<li><div class="src-line"><a name="a561"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a562"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Returns&nbsp;$this-&gt;modelLink</span></div></li>
<li><div class="src-line"><a name="a563"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a564"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodgetLinkModel">getLinkModel</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a565"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a566"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Result</span></div></li>
<li><div class="src-line"><a name="a567"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$modelLink">modelLink</a></span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a568"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a569"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a570"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a571"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;string&nbsp;getReference()</span></div></li>
<li><div class="src-line"><a name="a572"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a573"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Returns&nbsp;$this-&gt;reference</span></div></li>
<li><div class="src-line"><a name="a574"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a575"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodgetReference">getReference</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a576"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a577"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Result</span></div></li>
<li><div class="src-line"><a name="a578"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$reference">reference</a></span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a579"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a580"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a581"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a582"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;int&nbsp;getCardinality()</span></div></li>
<li><div class="src-line"><a name="a583"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a584"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Returns&nbsp;$this-&gt;cardinality</span></div></li>
<li><div class="src-line"><a name="a585"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a586"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodgetCardinality">getCardinality</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a587"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a588"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Result</span></div></li>
<li><div class="src-line"><a name="a589"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$cardinality">cardinality</a></span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a590"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a591"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a592"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a593"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;int&nbsp;getLimit()</span></div></li>
<li><div class="src-line"><a name="a594"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a595"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Returns&nbsp;$this-&gt;limit</span></div></li>
<li><div class="src-line"><a name="a596"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a597"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodgetLimit">getLimit</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a598"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a599"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Result</span></div></li>
<li><div class="src-line"><a name="a600"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$limit">limit</a></span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a601"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a602"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a603"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodgetNativeKey">getNativeKey</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a604"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$nativeKey">nativeKey</a></span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a605"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a606"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a607"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodgetForeignKey">getForeignKey</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a608"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$foreignKey">foreignKey</a></span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a609"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a610"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a611"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a612"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;bool&nbsp;getOption(&nbsp;string&nbsp;$option&nbsp;)</span></div></li>
<li><div class="src-line"><a name="a613"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;$option&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;Name&nbsp;of&nbsp;the&nbsp;option&nbsp;to&nbsp;find</span></div></li>
<li><div class="src-line"><a name="a614"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a615"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Returns&nbsp;TRUE&nbsp;if&nbsp;the&nbsp;specified&nbsp;option&nbsp;has&nbsp;been&nbsp;set,&nbsp;FALSE&nbsp;otherwise.</span></div></li>
<li><div class="src-line"><a name="a616"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a617"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodgetOption">getOption</a><span class="src-sym">(</span><span class="src-var">$option</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a618"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a619"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Result</span></div></li>
<li><div class="src-line"><a name="a620"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><a href="http://www.php.net/in_array">in_array</a><span class="src-sym">(</span><span class="src-var">$option</span><span class="src-sym">,&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$options">options</a></span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a621"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a622"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a623"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a624"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;bool&nbsp;isRecursive()</span></div></li>
<li><div class="src-line"><a name="a625"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a626"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Returns&nbsp;$this-&gt;isRecursive</span></div></li>
<li><div class="src-line"><a name="a627"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a628"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodisRecursive">isRecursive</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a629"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a630"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Result</span></div></li>
<li><div class="src-line"><a name="a631"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#methodisRecursive">isRecursive</a><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a632"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a633"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a634"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodisManyToManyPartial">isManyToManyPartial</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a635"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-sym">!</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#methodisManyToMany">isManyToMany</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span>&amp;&amp;&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#methodgetLinkModel">getLinkModel</a><span class="src-sym">(</span><span class="src-sym">)</span>!==<span class="src-id">NULL</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a636"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a637"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a638"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a639"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;bool&nbsp;isOneToOne()</span></div></li>
<li><div class="src-line"><a name="a640"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a641"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Returns&nbsp;TRUE&nbsp;if&nbsp;this&nbsp;is&nbsp;a&nbsp;1:1&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a642"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a643"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodisOneToOne">isOneToOne</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a644"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a645"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Result</span></div></li>
<li><div class="src-line"><a name="a646"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$cardinality">cardinality</a></span>==<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">ONE_TO_ONE</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a647"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a648"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a649"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a650"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;bool&nbsp;isOneToMany()</span></div></li>
<li><div class="src-line"><a name="a651"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a652"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Returns&nbsp;TRUE&nbsp;if&nbsp;this&nbsp;is&nbsp;a&nbsp;1:M&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a653"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a654"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodisOneToMany">isOneToMany</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a655"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a656"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Result</span></div></li>
<li><div class="src-line"><a name="a657"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$cardinality">cardinality</a></span>==<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">ONE_TO_MANY</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a658"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a659"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a660"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a661"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;bool&nbsp;isManyToOne()</span></div></li>
<li><div class="src-line"><a name="a662"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a663"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Returns&nbsp;TRUE&nbsp;if&nbsp;this&nbsp;is&nbsp;a&nbsp;M:1&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a664"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a665"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodisManyToOne">isManyToOne</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a666"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a667"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Result</span></div></li>
<li><div class="src-line"><a name="a668"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$cardinality">cardinality</a></span>==<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">MANY_TO_ONE</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a669"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a670"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a671"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a672"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;bool&nbsp;isManyToMany()</span></div></li>
<li><div class="src-line"><a name="a673"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a674"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Returns&nbsp;TRUE&nbsp;if&nbsp;this&nbsp;is&nbsp;a&nbsp;M:M&nbsp;relationship.</span></div></li>
<li><div class="src-line"><a name="a675"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a676"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodisManyToMany">isManyToMany</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a677"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a678"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Result</span></div></li>
<li><div class="src-line"><a name="a679"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$cardinality">cardinality</a></span>==<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">MANY_TO_MANY</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a680"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a681"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a682"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodgetManyToManyRelation">getManyToManyRelation</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a683"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a684"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#methodgetLinkModel">getLinkModel</a><span class="src-sym">(</span><span class="src-sym">)</span>===<span class="src-id">NULL&nbsp;</span>?&nbsp;<span class="src-key">new&nbsp;</span><span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span>:&nbsp;<span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">::</span><a href="../Buan/ModelRelation.html#methodgetRelation">getRelation</a><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#methodisOneToMany">isOneToMany</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span>?&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$modelSource">modelSource</a>&nbsp;</span>:&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$modelTarget">modelTarget</a></span><span class="src-sym">,&nbsp;</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id"><a href="../Buan/ModelRelation.html#var$modelLink">modelLink</a></span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a685"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a686"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a687"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">/*</span></div></li>
<li><div class="src-line"><a name="a688"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;@method&nbsp;ModelRelation&nbsp;getInverseRelation()</span></div></li>
<li><div class="src-line"><a name="a689"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#</span></div></li>
<li><div class="src-line"><a name="a690"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;Returns&nbsp;a&nbsp;ModelRelation&nbsp;object&nbsp;that&nbsp;describes&nbsp;the&nbsp;inverse&nbsp;relationship&nbsp;of&nbsp;$this.</span></div></li>
<li><div class="src-line"><a name="a691"></a><span class="src-comm">&nbsp;&nbsp;&nbsp;&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a692"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">public&nbsp;</span><span class="src-key">function&nbsp;</span><a href="../Buan/ModelRelation.html#methodgetInverseRelation">getInverseRelation</a><span class="src-sym">(</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a693"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a694"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Get&nbsp;attributes&nbsp;to&nbsp;be&nbsp;duplicated</span></div></li>
<li><div class="src-line"><a name="a695"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$modelSource&nbsp;</span>=&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#methodgetSourceModel">getSourceModel</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a696"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$modelTarget&nbsp;</span>=&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#methodgetTargetModel">getTargetModel</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a697"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$cardinality&nbsp;</span>=&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#methodgetCardinality">getCardinality</a><span class="src-sym">(</span><span class="src-sym">)</span>==<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">ONE_TO_MANY&nbsp;</span>?&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">MANY_TO_ONE&nbsp;</span>:&nbsp;<span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#methodgetCardinality">getCardinality</a><span class="src-sym">(</span><span class="src-sym">)</span>==<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">MANY_TO_ONE&nbsp;</span>?&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">ONE_TO_MANY&nbsp;</span>:&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#methodgetCardinality">getCardinality</a><span class="src-sym">(</span><span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a698"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$modelLink&nbsp;</span>=&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#methodgetLinkModel">getLinkModel</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a699"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$limit&nbsp;</span>=&nbsp;<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#methodgetLimit">getLimit</a><span class="src-sym">(</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a700"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a701"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;For&nbsp;recursive&nbsp;relationships&nbsp;we&nbsp;need&nbsp;to&nbsp;manually&nbsp;reverse&nbsp;the&nbsp;cardinality</span></div></li>
<li><div class="src-line"><a name="a702"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#methodisRecursive">isRecursive</a><span class="src-sym">(</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a703"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a704"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Determine&nbsp;the&nbsp;inverse&nbsp;relation&nbsp;reference</span></div></li>
<li><div class="src-line"><a name="a705"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$invRelationRef&nbsp;</span>=&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">REF_DEFAULT</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a706"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$modelTarget</span><span class="src-sym">]&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$ref</span>=&gt;<span class="src-var">$rel</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a707"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$ref</span>!=<span class="src-var">$this</span><span class="src-sym">-&gt;</span><span class="src-id">getReference</span><span class="src-sym">(</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a708"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$invRelationRef&nbsp;</span>=&nbsp;<span class="src-var">$ref</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a709"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a710"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a711"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a712"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Result</span></div></li>
<li><div class="src-line"><a name="a713"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-key">new&nbsp;</span><span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span></div></li>
<li><div class="src-line"><a name="a714"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelSource'</span>=&gt;<span class="src-var">$modelTarget</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a715"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelTarget'</span>=&gt;<span class="src-var">$modelSource</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a716"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'cardinality'</span>=&gt;<span class="src-var">$cardinality</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a717"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelLink'</span>=&gt;<span class="src-var">$modelLink</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a718"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'reference'</span>=&gt;<span class="src-var">$invRelationRef</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a719"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'limit'</span>=&gt;<span class="src-var">$limit</span></div></li>
<li><div class="src-line"><a name="a720"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a721"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a722"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a723"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Pre-defined&nbsp;relationships</span></div></li>
<li><div class="src-line"><a name="a724"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">else&nbsp;</span><span class="src-key">if</span><span class="src-sym">(</span>isset<span class="src-sym">(</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelTarget</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a725"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$invRelation&nbsp;</span>=&nbsp;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-var">$relationships</span><span class="src-sym">[</span><span class="src-var">$modelTarget</span><span class="src-sym">]</span><span class="src-sym">[</span><span class="src-var">$modelSource</span><span class="src-sym">]</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a726"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-id">count</span><span class="src-sym">(</span><span class="src-var">$invRelation</span><span class="src-sym">)</span>&gt;<span class="src-num">1</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a727"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">foreach</span><span class="src-sym">(</span><span class="src-var">$invRelation&nbsp;</span><span class="src-key">as&nbsp;</span><span class="src-var">$ref</span>=&gt;<span class="src-var">$rel</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a728"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if</span><span class="src-sym">(</span><span class="src-var">$ref</span>!=<span class="src-var">$this</span><span class="src-sym">-&gt;</span><a href="../Buan/ModelRelation.html#methodgetReference">getReference</a><span class="src-sym">(</span><span class="src-sym">))&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a729"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$rel</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a730"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a731"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a732"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a733"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">else&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a734"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$invRelation</span><span class="src-sym">[</span><span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">REF_DEFAULT</span><span class="src-sym">]</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a735"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a736"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a737"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a738"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;No&nbsp;inverse&nbsp;relationship&nbsp;found</span></div></li>
<li><div class="src-line"><a name="a739"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">else&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a740"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-key">new&nbsp;</span><span class="src-id"><a href="../Buan/ModelRelation.html">ModelRelation</a></span><span class="src-sym">(</span><span class="src-key">array</span><span class="src-sym">(</span></div></li>
<li><div class="src-line"><a name="a741"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelSource'</span>=&gt;<span class="src-var">$modelTarget</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a742"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'modelTarget'</span>=&gt;<span class="src-var">$modelSource</span><span class="src-sym">,&nbsp;</span></div></li>
<li><div class="src-line"><a name="a743"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'cardinality'</span>=&gt;<span class="src-id">self</span><span class="src-sym">::</span><span class="src-id">NONE</span></div></li>
<li><div class="src-line"><a name="a744"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a745"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a746"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a747"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a748"></a><span class="src-php">?&gt;</span></div></li>
</ol>
</span></div>
        <div class="credit">
		    <hr class="separator" />
		    Documentation generated on Tue, 04 Aug 2009 19:59:07 +0100 by <a href="http://www.phpdoc.org">phpDocumentor 1.4.1</a>
	      </div>
      </td></tr></table>
    </td>
  </tr>
</table>

</body>
</html>